import { Subject } from 'rxjs';

/**
 * 基础事件
 */
export default class BaseEvent {
  private static eventList: { [key: string]: Subject<any> } = {};

  /**
   * 获取事件
   * @param name  事件名
   * @returns
   */
  static getEvent(name: string) {
    !Object.prototype.hasOwnProperty.call(BaseEvent.eventList, name) &&
      (BaseEvent.eventList[name] = new Subject<any>());
    return BaseEvent.eventList[name];
  }

  /**
   * 移除
   * @param name 事件名
   */
  static removeEvent(name: string) {
    Object.prototype.hasOwnProperty.call(BaseEvent.eventList, name) && delete BaseEvent.eventList[name];
  }

  /**
   * 清空事件
   */
  static clearEvent() {
    BaseEvent.eventList = {};
  }
}
